/*
 * CompanyDB.h
 *
 *  Created on: Mar 25, 2014
 *      Author: alexander
 */

#ifndef COMPANYDB_H_
#define COMPANYDB_H_

#include <string>
#include <vector>
#include <map>
#include "CompanyData.h"
#include "Downloader.h"

class CompanyDB
{
public:
	void populateCompanyList();
	static std::map<std::string, CompanyData> populateCompanyList(const std::string& exchange);
	static std::map<std::string, CompanyData> populateCompanyList(const Downloader& d, const std::string& exchange);
	void showData(); // TODO
	void showData(const std::string& ticker);
	void populateFinancialData();
	void populateFinancialData(const std::string& symbol);
	void populateIncomeStatement(const std::string& ticker);
	void populateBalanceSheet(const std::string& ticker);
	void populateCashFlow(const std::string& ticker);
	void populateFinancialRatios(const std::string& ticker);
	void populateKeyStatistics(const std::string& ticker);
	static void parseFinancialsWebPage(std::vector<std::string> fetchedData, IncomeStatement& is);

	const std::map<std::string, CompanyData>& getCompanies() const {
		return companies;
	}

	void setCompanies(const std::map<std::string, CompanyData>& companies) {
		this->companies = companies;
	}

	void saveData() const;

	static void retrieveFinancials(
				const std::vector<std::string>& fetchedData, const std::vector<std::string>& years,
				const std::vector<std::string>& categories, const std::vector<std::string>& categoriesPerShare, int multiplier, std::map<std::string, std::map<std::string, float>>* financials);

private:
	int retrieveFinancialYears(const std::vector<std::string>& fetchedData,
			std::vector<std::string>& years);

	static const std::vector<std::string> EXCHANGES;
	static const std::string EXCHANGE_LIST_URL_1;
	static const std::string EXCHANGE_LIST_URL_2;
	std::map<std::string, CompanyData> companies;

};

#endif /* COMPANYDB_H_ */
